<!DOCTYPE html>
<!--
  ~ Copyright (C) 2018 Baidu, Inc. All Rights Reserved.
  -->
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="reLoad()">查询</button>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <input id="title_id" type="text" class="form-control" placeholder="商品名称">
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="is_onsale_id" class="form-control">
                            <option value="">选择上架状态</option>
                            <option value="0">未支付</option>
                            <option value="1">已支付</option>
                        </select>
                    </div>
                     <div class="columns pull-right col-md-2 nopadding">
                         <input id="order_no" type="text" class="form-control" placeholder="订单号">
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                         <input id="receiver" type="text" class="form-control" placeholder="收件人">
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                         <input id="mobile" type="text" class="form-control" placeholder="收件人手机">
                    </div>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">
                </table>
            </div>
        </div>
    </div>
    <!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
    <div>
        <script type="text/javascript">
            var s_edit_h = 'hidden';
            var s_remove_h = 'hidden';
        </script>
    </div>
    <div shiro:hasPermission="blog:bContent:edit">
        <script type="text/javascript">
            s_edit_h = '';
        </script>
    </div>
    <div shiro:hasPermission="blog:bContent:remove">
        <script type="text/javascript">
            var s_remove_h = '';
        </script>
    </div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" data-keyboard="true" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">修改发货状态</h4>
            </div>
            <div class="modal-body form-horizontal">
				<table class="table" id="orderDetailItem">
					<thead>
						<tr>
							<td>商品名称</td>
							<td>数量</td>
						</tr>
					</thead>
					<tbody>

					</tbody>
				</table>
                <div class="form-group">
                    <label class="col-sm-3 control-label" >修改发货状态</label>
                    <div class="col-sm-9">
                        <select class="form-control" id="model_shipping_status" name="orderStatusNew">
                            <option value="">选择发货状态</option>
                            <option value="0">未发货</option>
                            <option value="1">已发货</option>
                            <option value="2">已收货</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">快递公司</label>
                    <div class="col-sm-9">
                    <select class="form-control" id="model_shipping_channel" name="shippingChannel">
                            <option value="1">顺丰</option>
                            <option value="2">申通</option>
                            <option value="3">中通</option>
                            <option value="4">圆通</option>
                            <option value="5">韵达</option>
                            <option value="6">EMS</option>
                            <option value="7">天天快递</option>
                            <option value="8">百世汇通</option>
                            <option value="9">宅急送</option>
                            <option value="10">全峰快递</option>
                            <option value="11">邮政</option>
                            <option value="12">国通快递</option>
                            <option value="13">德邦快递</option>
                     </select>
                     </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label" for="model_status_new">快递单号</label>
                    <div class="col-sm-9">
                        <input class="form-control" type="text" name="shippingNo" id="model_shiipping_sn"/>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
            		<input type="hidden" id="model_id"/>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="model_modify_btn_id">修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<div th:include="include :: footer"></div>
<script language="javascript" type="text/javascript" src="/assets/javascript/bootstrap-typeahead.js"></script>
<script language="javascript" type="text/javascript" src="/assets/javascript/func.js"></script>
<script type="text/javascript">

    var prefix = "/order/list"

    $(function() {
        $.fn.typeahead.Constructor.prototype.blur = function () {
            var that = this;
            setTimeout(function () { that.hide() }, 250);
        };
        $("#username_id").typeahead({
            insertPoint:$("#username_id"),
            source: function (query, process) {
                $.get('/search_user?keyword=' + query + "&findChildren=0", "", function (data) {
                    process(data);
                })
            }
        });
        $("#model_modify_btn_id").click(function () {
            var shippingStatus = $("#model_shipping_status").val();
            var shippingChannel = $("#model_shipping_channel").val();
            var shiippingSn = $("#model_shiipping_sn").val();
            var id = $("#model_id").val();
            var data = {"id":id,"shippingStatus":shippingStatus,"shippingChannel":shippingChannel,"shiippingSn":shiippingSn};
            $.ajax({
                type: "POST",
                url: "/shop/order/consignment",
                data: JSON.stringify(data),
                dataType: "json",
                contentType:"application/json;charset=utf8",
                success: function(res){
                    if(res.code==0){
                        // 提交成功
                        alert('提交成功');
                        $("#myModal").modal('hide');
                        reLoad();
                    }else{
                        alert('提交失败，'+res.msg)
                    };
                },
                complete:function(){
                    isajax = false;
                }
            });
        });
        load();
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method : 'get', // 服务器数据的请求方式 get or post
                    url : "/shop/system/order/list", // 服务器数据的加载地址
                    // showRefresh : true,
                    // showToggle : true,
                    showColumns : true,
                    iconSize : 'outline',
                    toolbar : '#exampleToolbar',
                    striped : true, // 设置为true会有隔行变色效果
                    dataType : "json", // 服务器返回的数据类型
                    pagination : true, // 设置为true会在底部显示分页条
                    // queryParamsType : "limit",
                    // //设置为limit则会发送符合RESTFull格式的参数
                    singleSelect : false, // 设置为true将禁止多选
                    // contentType : "application/x-www-form-urlencoded",
                    // //发送到服务器的数据编码类型
                    pageSize : 10, // 如果设置了分页，每页数据条数
                    pageNumber : 1, // 如果设置了分布，首页页码
                    // search : true, // 是否显示搜索框
                    //showColumns : false, // 是否显示内容下拉框（选择显示的列）
                    sidePagination : "server", // 设置在哪里进行分页，可选值为"client" 或者
                    // "server"

                    queryParams : function(params) {
                        return {
                            // 说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                            limit : params.limit,
                            start : params.offset,
                            keyword : $("#title_id").val(),
                            isOnsale : $("#is_onsale_id").val(),
                            categoryId : $("#category_id").val(),
                            orderNo : $("#order_no").val(),
                            receiver : $("#receiver").val(),
                            mobile : $("#mobile").val()
                        };
                    },
                    // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                    // queryParamsType = 'limit' ,返回参数必须包含
                    // limit, offset, search, sort, order 否则, 需要包含:
                    // pageSize, pageNumber, searchText, sortName,
                    // sortOrder.
                    // 返回false将会终止请求
                    columns : [
                        {
                            visible : true,
                            field : 'id',
                            title : 'ID'
                        },
                        {
                            visible : true,
                            field : 'userId',
                            title : '购买人ID'
                        },
                        {
                            visible : true,
                            field : 'orderNo',
                            title : '订单号'
                        },
                        {
                            visible : true,
                            field : 'totalPayee',
                            title : '订单总金额'
                        },
                        {
                            visible : true,
                            field : 'receiver',
                            title : '收货人'
                        },
                        {
                            visible : true,
                            field : 'address',
                            title : '收货地址'
                        },
                        {
                            visible : true,
                            field : 'mobile',
                            title : '收货人电话'
                        },
                        {
                            field : 'orderStatusName',
                            title : '订单状态',
                        },
                        {
                            title : '操作',
                            field : 'id',
                            align : 'center',
                            formatter:function (value,row,index) {
                            		if(row.payStatus == 1){
                            			var e =
                                            '<a class="btn btn-primary btn-sm '+s_edit_h+'" data-toggle="modal" data-target="#myModal" href="#" mce_href="#" onclick="edit('+row.id+')">发货</a> ';
                                        return  e;
                            		}

                            }
                        }
                        ]
                });
    }
    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }
    function edit(cid) {
    		if(cid){
    			$("#model_id").val();
        		$("#model_shipping_status").val(0);
        		$("#model_shipping_channel").val(0);
        		$("#model_shiipping_sn").val("");
    			$.ajax({
    	            url : "/shop/order/detail/"+cid,
    	            type : "get",
    	            async: false,
    	            data : {},
    	            success : function(r) {
    	            		console.log(r);
    	                if (r.code == 0) {
    	                		$("#model_id").val(r.order.id);
    	                		$("#model_shipping_status").val(r.order.shippingStatus);
    	                		$("#model_shipping_channel").val(r.order.shippingChannel);
    	                		$("#model_shiipping_sn").val(r.order.shiippingSn);
    	                		$("#orderDetailItem tbody").empty();
    	                   for(var i = 0;i < r.order.orderDetails.length;i++){
    	                	    var detail = r.order.orderDetails[i];
    	                	   	$("#orderDetailItem tbody").append("<tr><td>"+detail.goodsName+"</td><td>"+detail.goodsNumber+"</td></tr>");
    	                   }
    	                } else {
    	                    layer.msg(r.msg);
    	                }
    	            }
    	        });
    		}
    }
    function preview(id) {
        window.open("/blog/open/post/"+id);
        //window.location.href="/blog/open/post/"+id;
    }

</script>
</body>
</html>
